// 管理员 独立，模块
import { userlist, usercount } from "../../../request/api";
const state ={
    //列表
    userlist:[],
    //页面显示的条数
    pageSize:3,
    //页码
    pageNum:1,
    //总条数
    count:0
};
const getters = {
getUser(state) {
    return state.userlist;
},
getSize(state) {
    return state.pageSize;
},
getCount(state) {
    return state.count;
  },
};
const mutations = {
  REQ_USERLIST(state, payload) {
    state.userlist = payload;
  },
  REQ_COUNT(state, payload) {
    state.count = payload;
  },
  //同步修改页码事件
  REQ_PAGE(state, payload) {
    state.pageNum = payload;
  },
};
const actions = {
  //获取管理员列表行动
  getUserAction(context) {
    // console.log(context, "context");
    userlist({
      size: context.state.pageSize, //查询条数
      page: context.state.pageNum, //页码
    }).then((res) => {
     
      context.commit("REQ_USERLIST", res.list);
    });
  },
  //获取总条数
  async getUserCount({ commit }) {
    let res = await usercount();
    commit("REQ_COUNT", res.list[0].total);
  },
  //获取当前页行动 调用列表行动
  changePageAction(context, payload) {
    //修改页码
    context.commit("REQ_PAGE", payload);
    //重新调用接口
    context.dispatch("getUserAction");
  },
};

export default {
  state,
  getters,
  mutations,
  actions,
  namespaced: true,
};
